import { defineConfig } from 'vite'

import vue from '@vitejs/plugin-vue'
// 打包文件大小分析工具
import { visualizer } from 'rollup-plugin-visualizer';
// Gzip 压缩
import viteCompression from "vite-plugin-compression";
//按需加载api
import AutoImport from 'unplugin-auto-import/vite'
//按需加载组件
import Components from 'unplugin-vue-components/vite'
import { AntDesignVueResolver,ElementPlusResolver} from 'unplugin-vue-components/resolvers'
// 引入css原子化
import tailwindcss from 'tailwindcss'

// https://vitejs.dev/config/
export default defineConfig({
  plugins: [
    vue(),
    visualizer({  
      open:true
    }),
    viteCompression({
      verbose: true,    
      disable: false, 
      threshold: 10240,  
      algorithm: 'gzip',
      ext: '.gz',  
    }),
    AutoImport({
      resolvers: [AntDesignVueResolver(),ElementPlusResolver()],
    }),
    Components({  
      resolvers: [AntDesignVueResolver(),ElementPlusResolver()],
    }),
  ],

  css:{
    postcss: {
      plugins: [
        tailwindcss({
          content: ['./src/**/*.vue']
        })
      ],
    }
  },

  build:{
    outDir:'dist',
    assetsDir:'assets',
    sourcemap:false,
    terserOptions:{
      compress:{
        drop_console:true,
        drop_debugger:true
      }
    },
    rollupOptions:{
      output:{ 
        chunkFileNames: 'static/js/[name]-[hash].js',      
        entryFileNames: 'static/js/[name]-[hash].js',      
        assetFileNames: 'static/[ext]/[name]-[hash].[ext]',
        manualChunks(id:any){ //静态资源拆分打包
          if (id.includes('node_modules')) {      
              return id.toString().split('node_modules/')[1].split('/')[0].toString();           }
       }

      }
    }
  },
  server: {
    proxy: {
      '/api': {
        target: "http://localhost", //跨域地址
        changeOrigin: true, //支持跨域
        

      }
    },
  }
})




